using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Entities;
using BUS;
using Utility;

public partial class Admin_DonHangThem : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDropDownList();
        }
        txt_ngaydathang.Text = DateTime.Now.ToString("dd/MM/yyyy");
        
    }
    private void LoadDropDownList()
    {
        tbKhachHangCollection khCollection = tbKhachHangBUS.GetAll();
        ddl_khachhang.DataTextField = tbKhachHangColumns.HoTen.ToString();
        ddl_khachhang.DataValueField = tbKhachHangColumns.MaKH.ToString();
        ddl_khachhang.DataSource = khCollection;
        ddl_khachhang.DataBind();
        ddl_khachhang.Items.Insert(0, new ListItem("All", "0"));

        tbTinhTrangThanhToanCollection ttttCollection = tbTinhTrangThanhToanBUS.GetAll();
        ddl_tinhtrangthanhtoan.DataTextField = tbTinhTrangThanhToanColumns.TenTTTT.ToString();
        ddl_tinhtrangthanhtoan.DataValueField = tbTinhTrangThanhToanColumns.MaTTTT.ToString();
        ddl_tinhtrangthanhtoan.DataSource = ttttCollection;
        ddl_tinhtrangthanhtoan.DataBind();
        ddl_tinhtrangthanhtoan.Items.Insert(0, new ListItem("All", "0"));

        tbTinhTrangGHCollection ttghCollection = tbTinhTrangGHBUS.GetAll();
        ddl_tinhtranggiaohang.DataTextField = tbTinhTrangGHColumns.TenTTGH.ToString();
        ddl_tinhtranggiaohang.DataValueField = tbTinhTrangGHColumns.MaTTGH.ToString();
        ddl_tinhtranggiaohang.DataSource = ttghCollection;
        ddl_tinhtranggiaohang.DataBind();
        ddl_tinhtranggiaohang.Items.Insert(0, new ListItem("All", "0"));

        tbPhuongThucThanhToanCollection ptttCollection = tbPhuongThucThanhToanBUS.GetAll();
        ddl_phuongthucthanhtoan.DataTextField = tbPhuongThucThanhToanColumns.TenPTTT.ToString();
        ddl_phuongthucthanhtoan.DataValueField = tbPhuongThucThanhToanColumns.MaPTTT.ToString();
        ddl_phuongthucthanhtoan.DataSource = ptttCollection;
        ddl_phuongthucthanhtoan.DataBind();
        ddl_phuongthucthanhtoan.Items.Insert(0, new ListItem("All", "0"));

        tbNhanVienCollection nvCollection = tbNhanVienBUS.GetAll();
        ddl_nhanviengiaohang.DataTextField = tbNhanVienColumns.TenNV.ToString();
        ddl_nhanviengiaohang.DataValueField = tbNhanVienColumns.MaNV.ToString();
        ddl_nhanviengiaohang.DataSource = nvCollection;
        ddl_nhanviengiaohang.DataBind();
        ddl_nhanviengiaohang.Items.Insert(0, new ListItem("All", "0"));

        tbDiaDiemCollection ddCollection = tbDiaDiemBUS.GetAll();
        ddl_diachigiaohang.DataTextField = tbDiaDiemColumns.DiaChi.ToString();
        ddl_diachigiaohang.DataValueField = tbDiaDiemColumns.MaDD.ToString();
        ddl_diachigiaohang.DataSource = ddCollection;
        ddl_diachigiaohang.DataBind();
        ddl_diachigiaohang.Items.Insert(0, new ListItem("All", "0"));
        
    }
    protected void btn_Add_Click(object sender, EventArgs e)
    {
        try
        {
            tbDonHang  donhang = new tbDonHang ();
            donhang.KhachHang = int.Parse(ddl_khachhang.SelectedValue);
            donhang.NgayDatHang = DateTime.Parse(txt_ngaydathang.Text);
            donhang.NgayGiaoHang = DateTime.Parse(txt_ngaygiaohang.Text);
            donhang.TriGia = int.Parse(txt_trigia.Text);
            donhang.TinhTrangGH = int.Parse(ddl_tinhtranggiaohang.SelectedValue);
            donhang.PhuongThucThanhToan = int.Parse(ddl_phuongthucthanhtoan.SelectedValue);
            donhang.TinhTrangThanhToan = int.Parse(ddl_tinhtrangthanhtoan.SelectedValue);
            donhang.NhanVienGiaoHang = int.Parse(ddl_nhanviengiaohang.SelectedValue);
            donhang.DiaChiGH = int.Parse(ddl_diachigiaohang.SelectedValue);
            tbDonHangBUS.Insert(donhang);
            Response.Redirect("~/Admin/DonHangDanhSach.aspx");
        }
        catch (Exception ex)
        {

        }
        Response.Redirect("~/Admin/DonHangDanhSach.aspx");

    }
}
